
import {
  getAllStore,
  getAllBrand,
  getSeries,
  getModelTimeType,
  getModelRank
} from '@/api/common'
const others = {
  namespaced: true,
  state: {
    dialog: {
      visible: false,
      title: '',
      width: '30%',
      params: {}
    },
    allStores: [],
    allCarList: {
      brandsList: [],
      seriesList: [],
      timeTypeList: [],
      modelList: []
    }

  },
  mutations: {
    SET_DIALOG: (state, obj) => {
      state.dialog = { ...state.dialog, ...obj }
    },
    SET_STORES: (state, list) => {
      state.allStores = list
    },
    SET_BRANDS: (state, list) => {
      state.allCarList = {
        ...state.allCarList,
        brandsList:list,
      }
    },
    SET_SERIES: (state, list) => {
      state.allCarList = {
        ...state.allCarList,
        seriesList:list,
      }
    },
    SET_TIME_TYPES: (state, list) => {
      state.allCarList = {
        ...state.allCarList,
        timeTypeList:list,
      }
    },
    SET_MODELS: (state, list) => {
      state.allCarList = {
        ...state.allCarList,
        modelList:list,
      }
    },
    SET_CLEAN:(state, list) => {
      state.allCarList = {
        ...state.allCarList,
        ...list
      }
    },
  },
  actions: {
    setDialog({ commit }, obj) {
      commit('SET_DIALOG', obj)
    },
    async setAllStores({ commit }) {
      const { data, success } = await getAllStore();
      if (success) {
        console.log(data,'---------')
        commit('SET_STORES', data)
      }
    },
    async setAllBrand({ commit }) {
      const {success, data } = await getAllBrand();
      if (success) {
        commit('SET_BRANDS', data)
      }
    },
    async setSeries({ commit }, brandId) {
      const { success,data } = await getSeries(brandId);
      if (success) {
        commit('SET_SERIES', data)
      }
    },
    async setModelTimeType({ commit }, {brandId,seriesId}) {
      const { success,data } = await getModelTimeType(brandId,seriesId);
      if (success) {
        commit('SET_TIME_TYPES', data)
      }
    },
    async setModelRank({ commit }, {brandId,seriesId,timeType}) {
      const { success,data } = await getModelRank(brandId,seriesId,timeType);
      if (success) {
        let list =data.map(item=>{
          return{
            ...item,
            id:item.id.toString()
          }
        })
        commit('SET_MODELS', list)
      }
    },
    async setCleanCar({ commit },data) {

        commit('SET_CLEAN',data)
      
    }

  }
}

export default others
